package com.wmcsk;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.hpplay.bean.CastDeviceInfo;
import com.hpplay.bean.WebPushInfo;
import com.hpplay.callback.CastDeviceCallback;
import com.hpplay.callback.CastDeviceServiceCallback;
import com.hpplay.callback.ConnectStateCallback;
import com.hpplay.callback.ExecuteResultCallBack;
import com.hpplay.callback.HpplayWindowPlayCallBack;
import com.hpplay.callback.MirrorStateCallback;
import com.wmcsk.dl.util.LogUtils;
import com.wmcsk.interfaces.InitResultListener;
import com.wmcsk.interfaces.KuaiyanVideoShadowSdkInterface;
import java.util.List;
/**
 * Created by wm on 2018/3/21.
 */
public class KuaiyanVideoShadowSdk implements KuaiyanVideoShadowSdkInterface{
    private static KuaiyanVideoShadowSdk kuaiyanSdk;
    public static final String ERROR_TAG = "KuaiyanVideoShadowSdk";
    private KuaiyanVideoShadowSdk(){

    }
    private KuaiyanVideoShadowSdkInterface kuaiyanSignSdkInterface;
    public void initKYSdkInterface(KuaiyanVideoShadowSdkInterface kuaiyanSignSdkInterface){
        this.kuaiyanSignSdkInterface = kuaiyanSignSdkInterface;
    }
    public static KuaiyanVideoShadowSdk getInstance(){
        if(kuaiyanSdk == null){
            synchronized (KuaiyanSdk.class){
                if(kuaiyanSdk == null){
                    kuaiyanSdk = new KuaiyanVideoShadowSdk();
                }
            }
        }
        return kuaiyanSdk;
    }
    @Override
    public String getVersion() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSignSdkInterface.getVersion();
    }

    @Override
    public void init(Context context, InitResultListener initResultListener) {
        if(kuaiyanSignSdkInterface == null) {
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            if(initResultListener!=null){
                initResultListener.initResult(-10);
            }
            return;
        }
        kuaiyanSignSdkInterface.init(context,initResultListener);
    }

    @Override
    public String getSdkInfo() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return "null";
        }
        return kuaiyanSignSdkInterface.getSdkInfo();
    }

    @Override
    public void castServiceDiscovery(Context context, CastDeviceServiceCallback castDeviceCallback) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return;
        }
        kuaiyanSignSdkInterface.castServiceDiscovery(context,castDeviceCallback);
    }

    @Override
    public void showHpplayWindow(Activity activity, HpplayWindowPlayCallBack hpplayWindowPlayCallBack) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return;
        }
        kuaiyanSignSdkInterface.showHpplayWindow(activity,hpplayWindowPlayCallBack);
    }

    @Override
    public void showHpplayWindow(Activity activity, String url, int position, HpplayWindowPlayCallBack hpplayWindowPlayCallBack, int pushType) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return;
        }
        kuaiyanSignSdkInterface.showHpplayWindow(activity,url,position,hpplayWindowPlayCallBack,pushType);
    }

    @Override
    public void showHpplayWindow(Activity activity, String url, HpplayWindowPlayCallBack hpplayWindowPlayCallBac, int pushType) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return;
        }
        kuaiyanSignSdkInterface.showHpplayWindow(activity,url,hpplayWindowPlayCallBac,pushType);
    }

    @Override
    public boolean isConnect() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return false;
        }
        return kuaiyanSignSdkInterface.isConnect();
    }

    @Override
    public boolean getMirrorState() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return false;
        }
        return kuaiyanSignSdkInterface.getMirrorState();
    }

    @Override
    public void castDisconnectDevice() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castDisconnectDevice();
    }

    @Override
    public void castServiceStopDiscovery() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castServiceStopDiscovery();
    }

    @Override
    public void castConnectDevice(CastDeviceInfo castDeviceInfo, ConnectStateCallback connectStateCallBack) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castConnectDevice(castDeviceInfo,connectStateCallBack);
    }

    @Override
    public void castStartMediaPlay(ExecuteResultCallBack ExecuteResultCallBack, int port, String url, int pushType) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castStartMediaPlay(ExecuteResultCallBack,port,url,pushType);
    }

    @Override
    public void castStartMediaPlay(ExecuteResultCallBack ExecuteResultCallBack, int port, String url, int pushType, int position) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castStartMediaPlay(ExecuteResultCallBack,port,url,pushType,position);
    }

    @Override
    public void castPlayControl(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isPlay) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castPlayControl(ExecuteResultCallBack,port,isPlay);
    }

    @Override
    public void castSeek(ExecuteResultCallBack ExecuteResultCallBack, int port, int rate) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castSeek(ExecuteResultCallBack,port,rate);
    }

    @Override
    public void castDeviceVolume(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isAddVolume) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castDeviceVolume(ExecuteResultCallBack,port,isAddVolume);
    }

    @Override
    public void castDeviceVolume(ExecuteResultCallBack ExecuteResultCallBack, int port, int volume) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castDeviceVolume(ExecuteResultCallBack,port,volume);
    }

    @Override
    public void stopPlay(ExecuteResultCallBack ExecuteResultCallBack, int port) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.stopPlay(ExecuteResultCallBack,port);
    }

    @Override
    public void castDeviceCallback(CastDeviceCallback castDeviceCallback) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castDeviceCallback(castDeviceCallback);
    }

    @Override
    public void setIsBackgroundPlay(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isBack) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setIsBackgroundPlay(ExecuteResultCallBack,port,isBack);
    }

    @Override
    public boolean isHasWebPush() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return false;
        }
        return kuaiyanSignSdkInterface.isHasWebPush();
    }

    @Override
    public void setWebPushSize(ExecuteResultCallBack ExecuteResultCallBack, int port, int size) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushSize(ExecuteResultCallBack,port,size);
    }

    @Override
    public void setWebPushIsBottom(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isBottom) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushIsBottom(ExecuteResultCallBack,port,isBottom);
    }

    @Override
    public void setWebPushOverlap(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isOverlap) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushOverlap(ExecuteResultCallBack,port,isOverlap);
    }

    @Override
    public void setWebPushVisibility(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isShow) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushVisibility(ExecuteResultCallBack,port,isShow);
    }

    @Override
    public void setWebPushPlay(ExecuteResultCallBack ExecuteResultCallBack, int port, boolean isPlay) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushPlay(ExecuteResultCallBack,port,isPlay);
    }

    @Override
    public void setWebPushAlpha(ExecuteResultCallBack ExecuteResultCallBack, int port, int alpha) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushAlpha(ExecuteResultCallBack,port,alpha);
    }

    @Override
    public void setWebPushMaxLine(ExecuteResultCallBack ExecuteResultCallBack, int port, int maxline) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushMaxLine(ExecuteResultCallBack,port,maxline);
    }

    @Override
    public void setWebPushSpeed(ExecuteResultCallBack ExecuteResultCallBack, int port, float speed) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setWebPushSpeed(ExecuteResultCallBack,port,speed);
    }

    @Override
    public void sendOtherBeantoJSon(ExecuteResultCallBack ExecuteResultCallBack, int port, List<WebPushInfo> webPushList, int type) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.sendOtherBeantoJSon(ExecuteResultCallBack,port,webPushList,type);
    }

    @Override
    public void sendOtherSingleBeantoJSon(ExecuteResultCallBack ExecuteResultCallBack, int port, WebPushInfo webPushInfo, int type) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.sendOtherSingleBeantoJSon(ExecuteResultCallBack,port,webPushInfo,type);
    }

    @Override
    public void sendUserSingleBeantoJSon(ExecuteResultCallBack ExecuteResultCallBack, int port, WebPushInfo webPushInfo, int type) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.sendUserSingleBeantoJSon(ExecuteResultCallBack,port,webPushInfo,type);
    }

    @Override
    public void castStartMirror(Activity activity, MirrorStateCallback mirrorStateCallBack) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castStartMirror(activity,mirrorStateCallBack);
    }

    @Override
    public void castStartMirrorResult(int requestCode, int resultCode, Intent data) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castStartMirrorResult(requestCode,resultCode,data);
    }

    @Override
    public void castStopMirror() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.castStopMirror();
    }

    @Override
    public void startPhotoPlay(ExecuteResultCallBack ExecuteResultCallBack, int port, String url) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.startPhotoPlay(ExecuteResultCallBack,port,url);
    }



    @Override
    public void stopPhotoPlay(ExecuteResultCallBack ExecuteResultCallBack, int port) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.stopPhotoPlay(ExecuteResultCallBack,port);
    }

    @Override
    public void quitPhotoPlay(ExecuteResultCallBack ExecuteResultCallBack, int port) {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.quitPhotoPlay(ExecuteResultCallBack,port);
    }

    @Override
    public Context getContext() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return null;
        }
        return kuaiyanSignSdkInterface.getContext();
    }

    @Override
    public void dismissHpplayWindow() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.dismissHpplayWindow();
    }

    @Override
    public CastDeviceInfo getCastDeviceInfo() {
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return null;
        }
       return kuaiyanSignSdkInterface.getCastDeviceInfo();
    }
    @Override
    public void setDebug(boolean debug){
        if(kuaiyanSignSdkInterface == null){
            LogUtils.getNewInstance(ERROR_TAG).eob("please wait sdkinit init complate");
            return ;
        }
        kuaiyanSignSdkInterface.setDebug(debug);
    }
}
